package com.shanghaionstar.mro.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.onstar.cn.common.log.LogManager;
import com.onstar.cn.map.common.PoiItemInfo;
import com.shanghaionstar.R;

import java.util.List;

public class MrOPoiListAdapter extends BaseAdapter {

	
	private List<PoiItemInfo> list;
	private Context context;
	public MrOPoiListAdapter(Context context, List<PoiItemInfo> list) {
		this.context = context;
		this.list = list;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(position > list.size()) {
			return null;
		}
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		if(convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.mro_poi_list_item, null);
			viewHolder = new ViewHolder();
			viewHolder.tv_mro_address_title = (TextView) convertView.findViewById(R.id.tv_mro_address_title);
			viewHolder.tv_mro_address = (TextView) convertView.findViewById(R.id.tv_mro_address);
			viewHolder.re_sendtocar = (RelativeLayout) convertView.findViewById(R.id.re_sendtocar);
			viewHolder.tv_mro_call = (TextView) convertView.findViewById(R.id.tv_mro_call);
			viewHolder.re_sendtocar.setTag(position);
			viewHolder.re_sendtocar.setOnClickListener(listener);
			convertView.setTag(viewHolder);
		}else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		String title = list.get(position).getTitle();
		String phone = list.get(position).getTelphone();
		LogManager.getInstance().i("title --->>" + title);
		String address = list.get(position).getAddress();
		viewHolder.tv_mro_address_title.setText(title);
		viewHolder.tv_mro_address.setText(address);
		viewHolder.tv_mro_call.setText(phone);
		return convertView;
	}
	
	private class ViewHolder {
		TextView tv_mro_address;
		TextView tv_mro_address_title;
		RelativeLayout re_sendtocar;
		TextView tv_mro_call;
	}
	
	private OnClickListener listener;
	public void setSendToCarListen(OnClickListener listener) {
		this.listener = listener;
	}
}
